package com.apes.crm.car.model;


import com.alibaba.fastjson.annotation.JSONField;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.ApesConst;
import com.apes.framework.util.DateUtil;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.Date;

@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = CarMaintenance.CONST_TABLE_NAME, indexes = {@Index(name = "idx_crm_car_maintenance", columnList = "CAR_ID", unique = true)})
public class CarMaintenance extends Model {
    public static final String CONST_TABLE_NAME = "crm_car_maintenance";

    @Id
    @Column(name = "id", nullable = false, length = 24)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "车辆保养信息", padding = 8)
    private String id; // id

    @OneToOne(optional = false)
    @JoinColumn(name = "car_id",referencedColumnName = "id")
    private CarBase car; // 车辆id

    @Column(name = "drivened_mileage", nullable = false,columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    private double drivenedMileage = 0; // 已行驶里程

    @Column(name = "maintenance_cycle_date",nullable = false,columnDefinition = "number(4,0) default 0")
    private int MaintenanceCycleDate = 0; // 保养间隔时间

    @Column(name = "maintenance_cycle_mileage", nullable = false,columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    private double maintenanceCycleMileage = 0; // 保养间隔里程

    @JSONField(format = DateUtil.SHOW_DATETIME_FORMAT)
    @Temporal(TemporalType.DATE)
    @Column(name = "last_maintenance_date")
    private Date lastMaintenanceDate; // 上次保养日期

    @Column(name = "last_maintenance_mileage",nullable = false,columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    private double lastMaintenanceMileage = 0; // 上次保养里程

    @Column(name = "last_maintenance_oil")
    private String lastMaintenanceOil; // 上次保养用油

    @Column(name = "next_maintenance_mileage",nullable = false,columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    private double nextMaintenanceMileage = 0; // 下次保养里程

    @JSONField(format = DateUtil.SHOW_DATETIME_FORMAT)
    @Temporal(TemporalType.DATE)
    @Column(name = "next_maintenance_date")
    private Date nextMaintenanceDate; // 预计下次保养日期
}
